import java.util.ArrayList;
import java.util.List;

class Solution {
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        List<Integer> ret = new ArrayList<>();
        //下一个更大元素I
        int n = nums1.length;
        int m = nums2.length;
        for(int i = 0; i < n; i++){
            boolean flag = true;
            for(int j = 0; j < m; j++){
                if (nums1[i] == nums2[j]){
                    for(int k = j + 1; k < m; k++){
                        if (nums2[k] > nums1[i]){
                            ret.add(nums2[k]);
                            flag = false;
                            break;
                        }
                    }
                }
            }
            if (flag){
                ret.add(-1);
            }
        }
        int[] res = new int[ret.size()];
        for(int i = 0; i < ret.size(); i++){
            res[i] = ret.get(i);
        }
        return res;
    }
}
